package com.lipert.sk2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Receiver extends Thread{

	@Override
	public void run() {
		DatagramSocket socketIn = null;
		try {
			socketIn = new DatagramSocket(GUI.PRIVATE_PORT);
		} catch (SocketException e1) {
			
			e1.printStackTrace();
		}
		int i = 0;
		while(true){
			System.out.println(i++);
		
		byte buforIn[] = new byte [255]; 
		DatagramPacket packetIn = new DatagramPacket (buforIn, buforIn.length); 
		

		try {
			socketIn.receive(packetIn);
		} catch (IOException e) {
			
			e.printStackTrace();
		} 
		System.out.println((packetIn.getAddress()).getHostName() + " " + new String(packetIn.getData()).trim());
		System.out.println((packetIn.getAddress()).getHostName());
			GUI.privateHistoryArea.append(ServerReceiver.nickList
					.get(ServerReceiver.addressList.indexOf((packetIn
							.getAddress()).getHostAddress())) +": " + new String( (packetIn.getData()) ).trim() + "\n");
		}
	} 

}
